<template>
	<view class="">
		<z-paging ref="refPaging">
			
			<toLoad v-if="dataInfo.istoLoad"></toLoad>
			<view class="bgMinor2 heightAuto pd-24">
				<view class="">
					<uv-tabs :list="dataInfo.itemList" @click="clickList" lineWidth="60" :activeStyle="m_tabsActive"
						:inactiveStyle="m_tabsNoActive" :lineColor="m_lineColor" :current="dataInfo.current"></uv-tabs>
				</view>
       
				<view v-if="dataInfo.current == 0">
					<creativeCenter ref="creativeCenterRef0" v-if="dataInfo.current == 0" type="c" :id="dataInfo.id"
						:isShouw='-1' />
				</view>
			<!-- 	<view v-if="dataInfo.current == 1" style="visibility: hidden;">
					<creativeCenter v-if="dataInfo.current == 1" ref="creativeCenterRef1" type="b" :id="dataInfo.id"
						:isShouw='-1' />
				</view> 2025-05-08 -->  
				<view v-if="dataInfo.current === 1">
					
					<scroll-view scroll-y style="height:95vh;" @scrolltolower="onScrollToLower">
						<!-- 嵌套子组件 -->
						<myCreative ref="creativeCenterRef2" type='b' tabs="2" />
						<!-- 模拟一些内容 -->
						<view v-for="i in 1" :key="i" style="visibility: hidden">{{ i }}</view>
					</scroll-view>
					
				</view>
			</view>

			<template #bottom style="background-color: red;">
				<!-- ||dataInfo.current ==1  2025-05-08 -->
				<view class="pd-24  bgMinor2" v-if="dataInfo.current == 0 "
					style="margin-bottom: 50rpx;">
					<uv-button type="primary" text="合 成" @click="handleSynthesis"></uv-button>
					<!-- dataInfo.Imagination -->
				</view>
			</template>
		</z-paging>
	</view>
</template>

<script setup lang="ts">
	import { reactive, ref, watch } from 'vue';
	import { getWindowHeight } from '@/pages/util/getHeight';
	import { addOpen, loggedIn, addOpenTab } from '@/pages/util/hooks';
	import creativeCenter from './component/creative-center'
	import myCreative from './component/my-creative'
	import { onShow, onLoad,onBackPress } from '@dcloudio/uni-app';
	import Tusentu from './component/Tusentu'
	import { get, post, baseConfig } from '../../utils/request';
	import axios from "axios"
	import toLoad from '@/pages/toLoad.vue'
	import useLoginStore from '@/pinia-store/userInfoStore';

	const useLogin = useLoginStore();
	// console.log('useLoginuseLogin',useLogin);
	/** @name 数据 */
	const dataInfo = reactive({
		current: 0,
		itemList: [{ name: '文生图' },  { name: '我的创作' }],
		// { name: '' }, 2025-05-08
		remark: '', 
		tabs: '',
		id: '',
		istoLoad: false
	});
	const creativeCenterRef2 = ref(null)
	function onScrollToLower  () {
	  
	  creativeCenterRef2.value.BottomFUN();
	}

	/** @name 切换选择 */
	function clickList(e) {
		dataInfo.current = e.index
		console.log('eeeeeeee', e, dataInfo.current);
	}
	const { type, id, tab, current } = withDefaults(
		defineProps<{
			type : String;
			id : any;
			tab : String;
			current : any
			// info: Array<T>;
		}>(),
		{
			type: () => 'b',
			id: () => '',
			tab: () => '',
			current: () => ''
			// portraitImg: () => '',
			// clothingImg: () => '',
			// 默认值 a一键换装 b个性定制
			// info: () => null // 复杂数据类型使用函数返回的方式
		},

	);


	// 定义组件引用
	const creativeCenterRef0 = ref(null);
	const creativeCenterRef1 = ref(null);


	const handleSynthesis = async () => {
		try {
			// dataInfo.istoLoad = true
			// console.log(dataInfo.current)
			let selectedValues : any;
			if (dataInfo.current === 0) {
				selectedValues = creativeCenterRef0.value?.getSelectedValues();
			}  else if (dataInfo.current === 1) {
				selectedValues = creativeCenterRef2.value?.getSelectedValues();
			}
			selectedValues.type = dataInfo.current
			dataInfo.current = 1
			
			// 2025-05-08
			// let selectedValues : any;
			// if (dataInfo.current === 0) {
			// 	selectedValues = creativeCenterRef0.value?.getSelectedValues();
			// } else if (dataInfo.current === 1) {
			// 	selectedValues = creativeCenterRef1.value?.getSelectedValues();
			// } else if (dataInfo.current === 2) {
			// 	selectedValues = creativeCenterRef2.value?.getSelectedValues();
			// }
			// selectedValues.type = dataInfo.current
			// dataInfo.current = 2
			// 2025-05-08
			uni.setStorageSync('information', true)
			const data = selectedValues;
			const response = await post<{
				code : number; message : string
			}>('customized/add', data);
			// if (response) {
			// 	dataInfo.istoLoad = false
			// }
			if (response.code == 200) {

				uni.showToast({
					title: response.message,
					icon: 'success',
					duration: 2000
				});
			} else {
				uni.showToast({
					title: response.message,
					icon: 'error',
					duration: 2000
				});
				dataInfo.current = selectedValues.type
				uni.setStorageSync('information', false)

			}
			console.log(response);
		} catch (error) {
			console.error(error);
		}
	};


	onShow((options : any) => {
		// console.log(options)
		// console.log("")
		// if(options.id || id){
		// 	console.log(options.id || id)
		// 	dataInfo.id = options.id || id
		// }
		// console.log('我要获取到这个id'+ options.id)
		// if(options.tab){
		// 	dataInfo.tabs = options.tab 
		// }
		if (current == 'a') {
			dataInfo.id = options.id
			creativeCenterRef0.value?.getDetailsDataFun(options.id);
			console.log(dataInfo.id + "我要看看id在不在")
		}

		// if(options.current){
		// 	dataInfo.current = options.current 
		// }

		// // dataInfo.current = options.tab 
		// // 选择同款调跳过来的
		// if(options.id ){
		// 	dataInfo.id = options.id
		// }
	});

	onLoad((options : any) => {
		if (options.tab) {
			dataInfo.tabs = options.tab
		}

		if (options.current) {
			dataInfo.current = options.current
		}

		if (options.id || id) {
			dataInfo.id = options.id || id
		}     
		if (current == 'b') {
			creativeCenterRef1.value?.fetchData();
			// creativeCenterRef0.value?.fetchData();
			// creativeCenterRef1.value?.getDetailsDataFun(id);
		}
		if (current == 'a') {
			dataInfo.id = options.id
			creativeCenterRef1.value?.fetchDataTwo();
			// creativeCenterRef0.value?.fetchData();
			// creativeCenterRef0.value?.getDetailsDataFun(options.id);
			// console.log(dataInfo.id+"我要看看id在不在")
		}



	})
	
	
</script>
<style>
	.zp-page-bottom-container {
		background: rgb(238, 238, 238);
	}
</style>
<style scoped lang="scss">
	// :deep(.checklist-box) {
	// 	//  模版
	// }
</style>